<!--#include file="../nav/account_top.php" -->
<!--#include file="../nav_menu/account_begin.php" -->
<style type="text/css">

/* 账单表格 */
table.ordertb {
border-collapse: collapse;
width: 100%;
font-size: 12px;
color:#333333;
}
table.ordertb tbody#tbnobody, table.ordertb tbody#tbloading {
display: none;
}
table.ordertb td {
background-color: #FFFFFF;
padding:5px;
text-align: center;
vertical-align:top;

}

table.ordertb tr.kong_row td{
height:8px;
line-height:8px;
padding:0px;
margin:0px;
}

table.ordertb thead th {
background: url("/misc/images/account/ordertbbg.jpg") repeat-x scroll center bottom #FFFFFF;
height:33px;
border-bottom: 1px solid #C4D5E0;
border-top: 1px solid #C4D5E0;
color: #000000;
height: 33px;
text-align: center;

}


table.ordertb td.ord_t{
background-color:#F3F3F3;
color:#404040;
text-align:left;
padding:10px;
border:1px solid #E6E6E6;
}
table.ordertb td.ord{

border:1px solid #E6E6E6;
}


table.ordertb td.ord_left{
text-align:left;
}
table.ordertb td.ord_right{
text-align:right;
}
table.ordertb td.ord_noborderl{
border-left:0px;
}
table.ordertb td.ord_noborderr{
border-right:0px;
}
table.ordertb td.ord_noborder{
border-left:0px;
border-right:0px;
}


div.created_div{
float:right;
color:#aaa;
}
 
.div_cname{
font-size:14px;
font-weight:bold;
margin-bottom:10px;
}
.div_cvege{
border: 1px dashed #CCCCCC;
color: #006600;
float: left;
margin-bottom: 10px;
margin-right: 10px;
padding: 5px 10px;
}

/* 订单提醒层 */
.div_orderalert{
background-color:#FFFFE0;
border:1px solid #F9DFB2;
color:#404040;
padding:10px;
}
.div_orderalert a span{
color:#CC3333;
}
.div_orderalert a{
margin-right:20px;
}
.div_orderalert a:hover{
color:#ff6600;
}
.div_orderalert a:hover span{
color:#ff6600;
}

</style>
<div class="main_content_title">
	我的订单
</div>
<div class="main_content_main">
	
	<div class="div_orderalert">
		我的订单提醒：
		<a href="javascript:void(0)" onclick="fnLoadGrid('')" >全部订单<span id="ordern_all">()</span></a>
		<a href="javascript:void(0)" onclick="fnLoadGrid(1)" >等待审核<span id="ordern_waitsh">()</span></a>
		<a href="javascript:void(0)" onclick="fnLoadGrid(2)" >即将发货<span id="ordern_waitsend">()</span></a>
		<a href="javascript:void(0)" onclick="fnLoadGrid(3)" >已经发货<span id="ordern_send">()</span></a>
		<a href="javascript:void(0)" onclick="fnLoadGrid(4)" >取消的订单<span id="ordern_cancel">()</span></a>
	</div>
	 
	<!--订单表格-->
	<div class="margin10">
		<table class="ordertb">
			<thead>
				<tr>
					<th style="width:250px">商品</th>
					<th style="width:60px;">单价</th>
					<th style="width:60px;">数量</th>
					<th style="width:160px;">总金额</th>
					<th style="width:100px;">状态</th>
					<th style="width:80px;">操作</th>
				</tr>
				<tr class="kong_row">
					<td colspan="6">&nbsp;</td>
				</tr>
			</thead>		
			<tbody id="tbdata"> 
<!--				<tr>
					<td class="ord_t" colspan="6">
						订单编号：20129093894829 提交时间：2012-12-11 12:22:59
					</td>
				</tr>
				<tr>
					<td class="ord ord_left ord_noborderr" >
						<div class="div_cname">金牌套餐A</div>
						<div class="div_citem">
							<div class="div_cvege">芹菜 1 份</div>
							<div class="div_cvege">南瓜 2 份</div>
							<div class="div_cvege">大蒜 3 份</div>
							<div class="clear"></div>
						</div>
					</td>
					<td class="ord ord_noborder" >
						￥10.00
					</td>
					<td class="ord ord_noborderl" >
						2
					</td>
					<td class="ord" rowspan="2" >
						<div class="fb f14 red">￥25.00</div>
					</td>
					<td class="ord" rowspan="2" >
						<span class="red">等待审核</span>
					</td>
					<td class="ord" rowspan="2" >
						<a href="#">取消订单</a>
					</td>
				</tr>
				<tr>
					<td class="ord ord_left ord_noborderr" >
						<div class="div_cname">金牌套餐B</div>
						<div class="div_citem">
							<div class="div_cvege">芹菜 1 份</div>
							<div class="div_cvege">南瓜 2 份</div>
							<div class="clear"></div>
						</div>
					</td>
					<td class="ord ord_noborder" >
						￥5.00
					</td>
					<td class="ord ord_noborderl" >
						1
					</td>
				</tr>
				<tr class="kong_row">
					<td colspan="6">&nbsp;</td>
				</tr>-->
			</tbody>
			<tbody id="tbnobody">
				<tr>
					<td colspan="6">
						暂无记录
					</td>
				</tr>
			</tbody>
			<tbody id="tbloading">
				<tr>
					<td colspan="6">
						<img src="/misc/images/account/loading.gif" title="正在加载" />
					</td>
				</tr>
			</tbody>	
		</table>	
	</div>
	<div id="grids"></div> 
	
	
</div>
<script type="text/javascript">
var url_list   =  '/account_order/index';
var url_cancelsubmit = '/account_order/cancelorder';
var url_ordernum = '/account_order/orderstatusnum';
$().ready(function(){
	o2js.build('o2grid');
	/* 组装表格 */	
	grids = new o2Grid({
		bind:'grids', 
		url:url_list,
		imgpath:'/misc/vendors/o2js/o2grid/image',
		rowNum:10,
		cols:[
		],
		beforefunc:function(){
			$('#tbdata').html('').hide(); 
			$('#tbnobody').hide(); 
			$('#tbloading').show();
		},
		runfunc:function(obj){
			details = obj.results; 
			if(details.length == 0){
				$('#tbdata').hide();
				$('#tbloading').hide();
				$('#tbnobody').show();
			}else{
				$('#tbloading').hide();
				$('#tbnobody').hide();
				$('#tbdata').show();
			}
			fnZuZhuangData(details);
		}
	});
	fnSearchs();
	
	fnGetOrderNum();
});
function fnSearchs(){
	grids.setBaseParams({
		types:''
	}); 
	grids.load(1); 
}
function fnLoadGrid(types){
	grids.setBaseParams({
		types:types
	}); 
	grids.load(1);
}
/* 组装联系人 */
function fnZuZhuangData(allrs){
	var html='';
	for(var i=0; i<allrs.length; i++){
		var obj = allrs[i];
		html += '		<tr>';
		html += '			<td class="ord_t" colspan="6">';
		html += '				订单编号：'+obj.code;
		html += ' &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;';
		html += '				送货时间：'+obj.rec_date+' '+obj.sendtime;
	//	html += ' &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;';
		html += '				<div class="created_div" title="下单时间：'+obj.created+'" >'+obj.created+'</div>';
		html += '			</td>';
		html += '		</tr>';
		var order_goods_num = obj.order_goods.length;
		for(var j=0; j<order_goods_num; j++){
			var j_obj = obj.order_goods[j];
			html += '		<tr>';
			html += '			<td class="ord ord_left ord_noborderr" >';
			html += '				<div class="div_cname">'+j_obj.combo_name+'</div>';
			html += '				<div class="div_citem">';
			for(var kk=0; kk<j_obj.order_goods_item.length; kk++){
				html += '					<div class="div_cvege">'+j_obj.order_goods_item[kk].vege_name+' '+j_obj.order_goods_item[kk].vege_num+' 份</div>';
			}
			html += '					<div class="clear"></div>';
			html += '				</div>';
			html += '			</td>';
			html += '			<td class="ord ord_noborder" >';
			html += '				￥'+j_obj.price;
			html += '			</td>';
			html += '			<td class="ord ord_noborderl" >';
			html += '				'+j_obj.nums;
			html += '			</td>';		
			if(j==0){
				html += '			<td class="ord" rowspan="'+order_goods_num+'" >';
				html += '				<div class="fb f14  ">￥'+obj.price_total+'</div>';
				html += '				<div class="margin10 gray">（含运费：￥'+obj.price_deliver+'）</div>';
				html += '			</td>';
				html += '			<td class="ord" rowspan="'+order_goods_num+'" >';
				//订单状态（-2：系统取消 -1：用户取消 0：待支付 1：支付完成，待审核 2：审核通过，待生产 3：生产完成，待配送 4：配送完成 ）
				switch(obj.status){
					case "-2":
						html += '				<span class="gray">系统取消</span>';
						break;
					case "-1":
						html += '				<span class="gray">用户取消</span>';
						html += '				<div class="gray" >'+obj.canceldate+'</div>';
						break;
					case "0":
						html += '				<span class="red">等待支付</span>';
						break;
					case "1":
						html += '				<span class="red">等待审核</span>';
						break;
					case "2":
						html += '				<span class="">即将发货</span>';
						break;
					case "3":
						html += '				<span class="">即将发货</span>';
						break;
					case "4":
						html += '				<span class="green">已经发货</span>';
						break;
					default:
						break;	
				}
				
				html += '			</td>';
				html += '			<td class="ord" rowspan="'+order_goods_num+'" >';
				if(obj.status == '1'){
					html += '				<a href="#" onclick="fnCancelOrder('+obj.id+')">取消订单</a>';
				}
				html += '			</td>';
				html += '		</tr>';
			}
			html += '		</tr>';
		}
		html += '		<tr class="kong_row">';
		html += '			<td colspan="6">&nbsp;</td>';
		html += '		</tr>';
	}					
	$('#tbdata').html(html);
}
/* 取消订单 */
function fnCancelOrder(id){	
	fnConfirm({
		str:"确认取消订单？",
		func_true:function(e){
			fnLoading('正在取消订单');
			$('button').attr('disabled','disabled');
			$.post(
				url_cancelsubmit,
				{
					id:id
				},
				function(e){
					fnLoadingEnd();
					$('button').attr('disabled','');
					var ok = errorHandler(e);
					if(ok && ok.success=="1"){　 
						grids.reload();
						fnGetOrderNum();
					}
				}
			);
		}
	});
}
/* 更新订单数量显示 */	
function fnGetOrderNum(){
	$.post(
		url_ordernum,
		{
		},
		function(e){
			var ok = errorHandler(e);
			if(ok && ok.success=="1"){　 
				$('#ordern_all').html('('+ok.allorder+')');
				$('#ordern_waitsh').html('('+ok.waitsh+')');
				$('#ordern_waitsend').html('('+ok.waitsend+')');
				$('#ordern_send').html('('+ok.send+')');
				$('#ordern_cancel').html('('+ok.cancel+')');
			}
		}
	);
}
</script>
<!--#include file="../nav_menu/account_end.php" -->
<!--#include file="../nav/account_bottom.php" -->